<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>تفاصيل الملحق</title>

<!------------------------------ajax---------------------------->
<!-- <script type="text/javascript"  src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script> 
    <script type="text/javascript"  src="http://malsup.github.com/jquery.form.js"></script> -->
	
<!---------------------for autocomplete--------------->
	<script type="text/javascript" src="<?php echo base_url('assets/js/jquery-1.11.0.min.js');?>" ></script>
	<script type="text/javascript" src="<?php echo base_url('assets/js/jquery-ui-1.10.4/js/jquery-ui-1.10.4.min.js');?>" ></script>
	<link href="<?php echo base_url("assets/css/jquery-ui.css")?>" rel="stylesheet" type="text/css" />
<!---------------------for form css ----------------------->
	<link href="<?php echo base_url("assets/css/pure.css")?>" rel="stylesheet" type="text/css" />
<!---------------------for form validation ----------------------->
<script type="text/javascript" src="<?php echo base_url('assets/js/jquery.validate.js');?>" ></script>
<!---------------------for form mask input ----------------------->
<script type="text/javascript" src="<?php echo base_url('assets/js/jquery.mask.min.js');?>" ></script>


</head>
<body>
<?php
include_once('header.php');
$result=$les_convention;  // one fournisseur
$produit=$produits;

// ----- populate $liste_des_fournisseurs array for autocomplete ----- //


$liste_des_produit = array();
foreach ($produit as $prod){
	array_push($liste_des_produit, $prod->dessignation);
}
// ----- populate $liste_des_activites array for autocomplete ----- //


?>
<?php
//echo form_open_multipart( base_url('convention_ctr/modifier_prod').'/'.$result[0]->id_convetion ); 

$montant_milier = number_format($montant, 2, ',', ' ');

if($montant>$max OR $montant<$min){
	echo('<div style="background-color:red">يجب ان يكون سعر الملحق ما بين '.$max.' و '.$min.'</div>');
}
?>

<form id="bc_form" class="pure-form pure-form-stacked" method="POST" action="<?php echo base_url('convention_annex_crt/modifier_convention').'/'.$result[0]->id_convention_annex;?>">
    
        <legend style="font-size: 150%">تفاصيل الملحق رقم: <?php echo('<strong>'.$result[0]->numero_annex.'</strong>');?></legend>

        <div class="pure-g">
             <div class="pure-u-1 pure-u-md-1-3" style="width: 30%">
                <label for="fournisseur">اسم المورد : </label>
				<label><?php echo($result[0]->nom);?></label>
            </div>
            
			<div class="pure-u-1 pure-u-md-1-3 " style="width: 30%">
                <label for="numero"> المادة : </label>
				<label><?php echo($result[0]->article);?></label>
                
            </div>
			
			 <div class="pure-u-1 pure-u-md-1-3 " style="width: 30%">
                <label style="display: inline-block" for="numero"> رقم الاتفاقية :</label>
				<label style="display: inline-block" class="ltr" > <?php echo($result[0]->numero_convention);?> </label>
                
            </div>
			
			 <div class="pure-u-1 pure-u-md-1-3 " style="width: 30%">
                <label style="display: inline-block" for="numero"> المبلغ :</label>
				<label style="display: inline-block" class="ltr" > <?php echo($montant_milier);?> </label>
                
            </div>
			
			 <div class="pure-u-1 pure-u-md-1-3 " style="width: 30%">
                <label for="article">التاريخ </label>
                <input  class="ltr" id="article" name="date" type="text" value="<?php echo($result[0]->date);?>">
            </div>
			
            <div class="pure-u-1 pure-u-md-1-3 " style="width: 30%">
                <label for="article">الرقم </label>
                <input  class="ltr" id="article" name="numero" type="text" value="<?php echo($result[0]->numero_annex);?>">
            </div>
			
			

           
			
		<!--	<div class="pure-u-1 pure-u-md-1-3 " style="width: 30%">
                <label for="numero"> الاستشارة </label>
				<input class="ltr" id="numer" name="consultaion" type="text" value="<?php echo($montant_milier);?>">
                
            </div>-->
			
			
			
			<div class="pure-u-1 pure-u-md-1-3 " style="width: 90%">
                <label for="numero"> المبلغ بالحروف </label>
				<?php echo($lettre);?>
                
            </div>
   </div>
<div class="pure-u-1 pure-u-md-1-3 " style="width: 50%">	
<?php
 
  $goupe=$this->session->userdata('user_group'); //access it
if($goupe=="admin"){
	
		echo('
		<a href="'. base_url("/convention_annex_crt/ajout_produit_annex").'/'.$result[0]->id_convention_annex.'/'.$result[0]->id_fournisseur.'" class="pure-button pure-button-primary">اضافة منتج</a>');
		
echo (' <input type="submit" id="ajouter" value="تسجيل التغييرات"  class="pure-button pure-button-primary" />
      	

	');

	}		
 			  


	
	?>		
	 <a href="<?php echo base_url("/convention_annex_crt/imprimer").'/'.$result[0]->id_convention_annex ?>" class="pure-button pure-button-primary">طباعة</a>
     <a href="<?php echo base_url("/convention_crt/")?>" class="pure-button pure-button-primary" >خروج</a>

	 <a <?php echo(' href=" '.  base_url("/convention_annex_crt/supprimer_annex/").'/'.$result[0]->id_convention_annex .'/'.$result[0]->id_convetion .' " ');?> class="pure-button pure-button-primary" onclick="return confirm('هل تريد فعلا حذف هذا الملحق');">حذف</a>
	 </div>
			
			
</form>
	
<?php

if($montant>0){ // test si il ya des produit dans le bc avant afficher
echo('
<div id="les prod" style="width: 90%; text-align: center; letter-spacing:0.5px;">
			<br>
			  <label style="font-size:150% ">	المنتجات التابعة لهذا الملحق </label>
				
			<br>
			</div>		');
$i=0;
foreach($result as $data) 
{
	$i++;
$table['num_prod']=$i;
$table['id_bc']=$data->id_convention_annex;
$prix=($data->pu * $data->quantite)+($data->pu * $data->quantite)*$data->tva/100;
$prix_milier = number_format($prix, 2, ',', ' ');




if($goupe=="admin" ){ // si il est administrateur on affiche des bottons
 echo '
 <form id="bc_form"  method="POST" action="'.base_url('convention_annex_crt/modifier_prod_annex').'/'.$i.'/'.$data->id_convention_annex.'/'.$data->id_produit.'">
			<div class="pure-u-1 pure-u-md-1-3 " style="width: 20%">
                <label for="numero"> المنتج </label>
				<input class="ltr" id="dessignation'.$i.'" name="dessignation'.$i.'" type="text" value="'.$data->dessignation.'">
                
            </div>
			<div class="pure-u-1 pure-u-md-1-3 " " style="width: 20%">
                <label for="numero">س و</label>
				<input class="ltr" id="pu" name="pu'.$i.'" type="text" value="'.$data->pu.'">
                
            </div>
			<div class="pure-u-1 pure-u-md-1-3 " " style="width: 20%">
                <label for="numero"> الكمية </label>
				<input class="ltr" id="quantite" name="quantite'.$i.'" type="text" value="'.$data->quantite.'">
                
            </div>
			<div class="pure-u-1 pure-u-md-1-3 " " style="width: 20%">
                <label for="numero"> المبلغ </label>
				
                <label style="display: inline-block" class="ltr"> '.$prix_milier.'</label>
            </div>
			<div  class="pure-u-1 pure-u-md-1-3" " style="width: 20%">
		<input type="submit" id="ajouter" value="تسجيل التغييرات"  class="pure-button pure-button-primary"  />
	   <a href="'.base_url("/convention_annex_crt/supprime_prod_annex").'/'.$data->id_convention_annex.'/'.$data->id_produit.'" class="pure-button pure-button-primary">حذف</a>
			 </div>
			 </form>
			';
			
	}else{
		 echo '
 <form id="bc_form"  method="POST" action="'.base_url('convention_annex_crt/modifier_prod').'/'.$i.'/'.$data->id_convention_annex.'">
			<div class="pure-u-1 pure-u-md-1-3 " style="width: 20%">
                <label for="numero"> المنتج </label>
				<input class="ltr" id="dessignation'.$i.'" name="dessignation'.$i.'" type="text" value="'.$data->dessignation.'">
                
            </div>
			<div class="pure-u-1 pure-u-md-1-3 " " style="width: 20%">
                <label for="numero">س و</label>
				<input class="ltr" id="pu" name="pu'.$i.'" type="text" value="'.$data->pu.'">
                
            </div>
			<div class="pure-u-1 pure-u-md-1-3 " " style="width: 20%">
                <label for="numero"> الكمية </label>
				<input class="ltr" id="quantite" name="quantite'.$i.'" type="text" value="'.$data->quantite.'">
                
            </div>
			<div class="pure-u-1 pure-u-md-1-3 " " style="width: 20%">
                <label for="numero"> المبلغ </label>
				
                <label style="display: inline-block" class="ltr"> '.$prix_milier.'</label>
            </div>
			
			 </form>
			';
	}		
			

	
}
$i++;
}else{
	echo '<div class="pure-u-1 pure-u-md-1-3 " " style="background-color:red; font-size: 200%; width:80% ">
                <label for="numero"> لا يوجد منتجات تابعة لهذا الملحق </label>
				               
            </div>';
}
?>
     
		</div>
     
			

		
</body>

<script>
$(document).ready(function() {

var liste_fourniss = <?php echo json_encode($liste_des_fournisseurs); ?>;
var liste_prod = <?php echo json_encode($liste_des_produit); ?>;
$( "#nom" ).autocomplete({source: liste_fourniss});
for(j=0;j<7;j++)	{
$( "#dessignation".concat(j) ).autocomplete({source: liste_prod});
}


});

//---



</script>
<script> 
 $(document).ready( function() {
	$('#send').click(function(){
		//    $("#bc_form").submit(function () {
	            $.post("<?php echo base_url("/bc_ctr/test/$i");?>",$("#bc_form").serialize(),function(texte){
	                        $("#ajout").append(texte);
							
					
	            });
				
				
	            return false; // ne change pas de page
				
                  
	    });
				
	});
	

</script>
</html>